package com.da.javatest.leetCode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author chenlida
 * @date 2019/1/4 11:07
 * @description
 */
public class Code349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>(nums1.length);
        for (int i : nums1) {
            set1.add(i);
        }
        Set<Integer> set2 = new HashSet<>(nums2.length);
        for (int i : nums2) {
            set2.add(i);
        }
        set1.retainAll(set2);
        int[] result = new int[set1.size()];
        int i = 0;
        for (Integer integer : set1) {
            result[i++] = integer;
        }
        return result;
    }
}
